<?php
require_once("model/loginBD.php");
function add_skillsBD($id_skill, $name_skill) {
	$query = "INSERT INTO skills (id_skill, name_skill) 
			  VALUES ( '".$_SESSION['id_user']."','".$name_skill."' )";
	logIn();
	$rs = mysql_query($query); //or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	if (!$rs)
		return false;
	return true;
}

function select_skill() {
	$query = "SELECT id_skill, name_skill FROM skills ORDER BY id_skill"; 
								 
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		$i = 0;
		while($row = mysql_fetch_array($result)) {
			$tab['id_skill'][$i] = $row['id_skill'];
			$tab['name_skill'][$i] = $row['name_skill'];
			++$i;
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}

function view_skillsBD($id_skill) {
	$query = "SELECT id_skill, name_skill FROM skills
			  WHERE id_skill = '".$id_skill."'"; 
			  
	logIn();
	$result = mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());	
	logOut();
	$total = mysql_num_rows($result);
	if($total) {
		
		while($row = mysql_fetch_array($result)) {
			$tab['id_skill'][] = $row['id_skill'];
			$tab['name_skill'][] = $row['name_skill'];
			
		}
	}
	if( mysql_num_rows($result) > 0) return $tab;	else return 0;
}


function delete_skill_db($id_skill) {
	$query = "DELETE FROM skills WHERE (id_skill = '".$id_skill."')";
	logIn();
	mysql_query($query) or die('Erreur SQL !'.$query.'<br>'.mysql_error());
	logOut();
	return true;
}

?>